<template>
  <div>
    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="点位搜索：">
          <el-input v-model="formInline.name" placeholder="请输入" clearable />
        </el-form-item>
        <el-form-item label="区域搜索：">
          <el-select v-model="formInline.regionId" placeholder="请选择" filterable clearable>
            <el-option v-for="item in reviseList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="searchTop">查询</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card">
      <el-row>
        <el-button type="warning" icon="el-icon-circle-plus-outline" class="icon-add" @click="createNew">新建</el-button>
      </el-row>
      <el-table :data="list">
        <el-table-column type="index" label="序号" />
        <el-table-column prop="name" label="点位名称" width="180" />
        <el-table-column prop="region.name" label="所在区域" width="180" />
        <el-table-column prop="businessType.name" label="商圈类型" width="100" />
        <el-table-column prop="ownerName" label="合作商" width="180" />
        <el-table-column prop="addr" label="详细地址" width="180" />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="mini" @click="seeDetails">查看详情</el-button>
            <el-button size="mini">修改</el-button>
            <el-button size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 新建 弹窗 -->
    <NewPoint :show="showNew" @close="closeNew" @submit="submitNew" />
    <!-- 查看详情 -->
  </div>
</template>

<script>
import NewPoint from './components/newPoint.vue'
import { searchPointApi, getPointApi } from '@/api'
export default {
  components: {
    NewPoint
  },
  data() {
    return {
      formInline: {
        reginoId: '', // 区域id
        name: '', // 点位名称
        id: null, // id
        ratio: '', // 分成比例
        contact: '', // 联系人
        phone: '' // 联系电话
      },
      list: [],
      reviseList: [],
      showNew: false
    }
  },
  created() {
    this.fatchSearchPointApi()
  },
  methods: {
    // 渲染页面
    async  fatchSearchPointApi(val) {
      const res = await searchPointApi(val)
      const res2 = await getPointApi()
      this.reviseList = res2.currentPageRecords

      this.list = res.currentPageRecords
    },
    // 上部 查询
    async  searchTop() {
      this.fatchSearchPointApi(this.formInline)
      console.log(this.formInline)
    },
    // 点击新建
    createNew() {
      this.showNew = true
    },
    // 关闭 新建 弹窗
    closeNew() {
      this.showNew = false
    },
    // 确认新建
    submitNew() {
      this.showNew = false
    },
    // 点击 查看详情
    seeDetails(val) {

    }
  }

}
</script>

<style lang="scss" scoped>
::v-deep .box-card{
  margin: 10px;
}
</style>
